<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta name="renderer" content="webkit">
		<meta charset="utf-8" />
		<title>登录 - <?=ADMIN_SYS_NAME?></title>
		
		<link rel="shortcut icon" href="<?=$staticAdminUrl?>assets/images/favicon.jpg">
		
		<meta name="description" content="User login page" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/font-awesome/4.7.0/css/font-awesome.min.css" />
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/net.css" />
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/bootstrap-multiselect.min.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="<?=$staticAdminUrl?>assets/css/ace-rtl.min.css" />
	</head>

	<body class="login-layout" style="background: #438eb9">
		<div id="login-div" class="main-container">
			<div class="login-image">
				<img src="<?=$staticAdminUrl?>assets/images/login-bg.jpg"/>	
			</div>
			<div class="login-form">
				<!-- <img class="login-logo" src="<?=$staticAdminUrl?>assets/images/login-logo.jpg" /> -->
				<form id="login-form" style="margin-top:130px">
					<div class="select-div">
						<select class="province-select"></select>
						<select class="city-select"></select>
						<select class="school-select" name="school"></select>
					</div>
					<input type="text" class="login-input" name="username" placeholder="请输入您的账号" />
					<input type="password" class="login-input" name="password" placeholder="请输入您的密码" />
					<input type="text" class="login-input login-captcha" name="captcha" maxlength="4" placeholder="请输入您的验证码" />
					<img id="captcha-img" src="<?=admin_url("login/captcha")?>" class="pull-right"/>
					<button class="login-btn" type="submit">登录</button>
				</form>
			</div>
		</div>
		<!-- <div id="login-footer">
			<p>
				<p>
					Copyright @2018 <a href="https://rongmixiao.com/" target="_blank" style="color:#FFF;">深圳市融米校教育科技有限公司</a>
				</p>
				<p>
					版权所有 粤ICP备19062589号-1
				</p>
			</p>
		</div>	 -->
		

		<script src="<?=$staticAdminUrl?>assets/js/jquery-2.1.4.min.js"></script>
		<script src="<?=$staticAdminUrl?>assets/js/bootstrap.min.js"></script>
		<script src="<?=$staticAdminUrl?>assets/js/net.js"></script>
		<script src="<?=$staticAdminUrl?>assets/js/bootstrap-multiselect.min.js"></script>
		<script src="<?=$staticAdminUrl?>assets/layer/layer.js"></script>

		<script src="<?=$staticAdminUrl?>assets/js/ace-elements.min.js"></script>
		<script src="<?=$staticAdminUrl?>assets/js/ace.min.js"></script>
		<script type="text/javascript">
			var addressData = <?=$schoolData?>;
			// localstorage
			var provinceCodeStorage = localStorage.getItem('province_code');
			var cityCodeStorage = localStorage.getItem('city_code');
			var schoolCodeStorage = localStorage.getItem('school_code');

			$(function(){
				// 下拉菜单美化
				$(".province-select, .city-select").multiselect({
					nonSelectedText: "请选择",
					buttonWidth: "97px",
				 	buttonClass: 'btn from-select',
				 	templates: {
						button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
				 	},
				 	onChange:function(e){
				 		if($(e).parent().hasClass("province-select")) load_city_select(false);
				 		if($(e).parent().hasClass("city-select")) load_school_select(false);
		        	}
				});
				$(".school-select").multiselect({
					nonSelectedText: "请选择",
					buttonWidth: "160px",
				 	buttonClass: 'btn from-select',
				 	templates: {
						button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
				 	}
				});

				// 生成省份数据
				var provinceData = new Array();
				if(provinceCodeStorage != null && addressData[provinceCodeStorage] != undefined) {
					provinceData.push({
						label: addressData[provinceCodeStorage].areaName,
						value: provinceCodeStorage
					})
				}
				for(var i in addressData) {
					if(i != provinceCodeStorage) {
						provinceData.push({
							label: addressData[i].areaName,
							value: i
						})
					}
				}
				$(".province-select").multiselect('dataprovider',provinceData);

				if(addressData.length != 0) {
					load_city_select();
				}

				var loginForm = $("#login-form");
				var loginUrl = "<?=admin_url("login/login_action")?>";
				form_submit(loginForm, loginUrl, function(res) {
					tips_alert(res.msg, res.success, function(){
						// console.log(res);return;
						if(res.success) {
							// 保存地区localstorage
							localStorage.setItem('province_code', $(".province-select").val());
							localStorage.setItem('city_code', $(".city-select").val());
							localStorage.setItem('school_code', $(".school-select").val());

							window.location.href = "<?=admin_url("home/index")?>";
						} else {
							reset_captcha();
						}
					});
				})

				// 点击切换验证码
				$('#captcha-img').click(function(){
					reset_captcha();
				})
			})
			// 刷新验证码
			function reset_captcha(){
				var captchaImg = "<?=admin_url("login/captcha")?>?time=" + Date.parse(new Date());
				$("#captcha-img").attr("src", captchaImg);
			}

			// 加载城市数据（首次加载，记忆上次选择）
			function load_city_select($firstLoad = true){
				var provinceCode = $(".province-select").val();
				var cityDataSource = addressData[provinceCode];
				var cityData = new Array();

				if($firstLoad) {
					if(cityCodeStorage != null  && cityDataSource['city'][cityCodeStorage] != undefined) {
						cityData.push({
							label: cityDataSource['city'][cityCodeStorage].areaName,
							value: cityCodeStorage
						})
					}
					for(var i in cityDataSource['city']) {
						if(i != cityCodeStorage) {
							cityData.push({
								label: cityDataSource['city'][i].areaName,
								value: i
							})
						}
					}
				} else {
					for(var i in cityDataSource['city']) {
						cityData.push({
							label: cityDataSource['city'][i].areaName,
							value: i
						})
					}
				}

				$(".city-select").multiselect('dataprovider',cityData);
				load_school_select($firstLoad);
			}
			// 加载学校数据（首次加载，记忆上次选择）
			function load_school_select($firstLoad = true){
				var provinceCode = $(".province-select").val();
				var cityCode = $(".city-select").val();
				var schoolDataSource = addressData[provinceCode]['city'][cityCode]['school'];
				var schoolData = new Array();

				if($firstLoad) {
					var schoolName = '';
					for(var i in schoolDataSource) {
						if(schoolDataSource[i]['id'] == schoolCodeStorage) {
							schoolName = schoolDataSource[i]['name'];
						}
					}
					if(schoolCodeStorage != null && schoolName != '') {
						schoolData.push({
							label: schoolName,
							value: schoolCodeStorage
						})
					}
					for(var i in schoolDataSource) {
						if(schoolDataSource[i]['id'] != schoolCodeStorage) {
							schoolData.push({
								label: schoolDataSource[i].name,
								value: schoolDataSource[i].id
							})
						}
					}
				} else {
					for(var i in schoolDataSource) {
						schoolData.push({
							label: schoolDataSource[i].name,
							value: schoolDataSource[i].id
						})
					}
				}

				$(".school-select").multiselect('dataprovider',schoolData);
			}
		</script>
	</body>
</html>
